﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class AdminDAL
    {
        SQLHelper SQLHelper = null;
        QXHelper QXHelper = null;
        public AdminDAL()
        {
            SQLHelper = new SQLHelper();
            QXHelper = new QXHelper();
        }

        //start 系统菜单管理部分
        #region 显示所有菜单
        public string jhy_menu_query()
        {
            DataTable dt = new DataTable();
            string proc = "jhy_menu_query";
            dt = SQLHelper.ExecuteQuery(proc, CommandType.StoredProcedure);
            return QXHelper.LayuiTableJson(dt);
        }
        #endregion
        #region 显示所有菜单组
        public string jhy_menugroup_query()
        {
            DataTable dt = new DataTable();
            string proc = "jhy_menugroup_query";
            dt = SQLHelper.ExecuteQuery(proc, CommandType.StoredProcedure);
            return QXHelper.LayuiTableJson(dt);
        }
        #endregion
        #region 添加菜单组
        public bool jhy_menugroup_add(string mg_name)
        {
            bool flag = false;
            string proc = "jhy_menugroup_add";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@mg_name",mg_name)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 删除菜单组
        public bool jhy_menugroup_delete(string mg_id)
        {
            bool flag = false;
            string proc = "jhy_menugroup_delete";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@mg_id",mg_id)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 修改菜单组
        public bool jhy_menugroup_edit(string mg_id, string mg_field, string mg_para)
        {
            bool flag = false;
            string proc = "jhy_menugroup_edit";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@mg_id",mg_id),
                new SqlParameter("@mg_field",mg_field),
                new SqlParameter("@mg_para",mg_para)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 添加菜单
        public bool jhy_menu_add(string menu_name, string menu_url, string mg_id)
        {
            bool flag = false;
            string proc = "jhy_menu_add";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@menu_name",menu_name),
                new SqlParameter("@menu_url",menu_url),
                new SqlParameter("@mg_id",mg_id)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 删除菜单
        public bool jhy_menu_delete(string menu_id)
        {
            bool flag = false;
            string proc = "jhy_menu_delete";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@menu_id",menu_id)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 修改菜单
        public bool jhy_menu_edit(string menu_id, string menu_field, string menu_para)
        {
            bool flag = false;
            string proc = "jhy_menu_edit";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@menu_id",menu_id),
                new SqlParameter("@menu_field",menu_field),
                new SqlParameter("@menu_para",menu_para)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion

        //end 系统菜单管理部分
        //start 系统角色管理部分
        #region 查询系统角色
        public string jhy_role_query()
        {
            DataTable dt = new DataTable();
            string proc = "jhy_role_query";
            dt = SQLHelper.ExecuteQuery(proc, CommandType.StoredProcedure);
            return QXHelper.LayuiTableJson(dt);
        }
        #endregion
        #region 添加系统角色
        public bool jhy_role_add(string role_name,string role_level)
        {
            bool flag = false;
            string proc = "jhy_role_add";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@role_name",role_name),
                new SqlParameter("@role_level",role_level)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 删除系统角色
        public bool jhy_role_delete(string role_id)
        {
            bool flag = false;
            string proc = "jhy_role_delete";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@role_id",role_id)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 修改系统角色
        public bool jhy_role_edit(string role_id,string role_field,string role_para)
        {
            bool flag = false;
            string proc = "jhy_role_edit";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@role_id",role_id),
                new SqlParameter("@role_field",role_field),
                new SqlParameter("@role_para",role_para)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 查询系统角色菜单
        public DataSet jhy_role_menu_query(string role_id)
        {
            DataSet ds = new DataSet();
            string proc = "jhy_role_menu_query";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@role_id",role_id)
            };
            ds = SQLHelper.ExecuteQueryDataSet(proc, spa, CommandType.StoredProcedure);
            return ds;
        }
        #endregion
        #region 系统角色菜单管理
        public bool jhy_role_menu_edit(string role_id, string menu_id, string field)
        {
            bool flag = false;
            string proc = "jhy_role_menu_edit";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@role_id",role_id),
                new SqlParameter("@menu_id",menu_id),
                new SqlParameter("@field",field)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        //end 系统角色管理部分
        //start 网站配置
        #region 网站配置
        public bool jhy_site_update(string site_logotext,string site_logoicon,string site_notice,string site_copyright,string site_about)
        {
            bool flag = false;
            string proc = "jhy_site_update";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@site_logotext",site_logotext),
                new SqlParameter("@site_logoicon",site_logoicon),
                new SqlParameter("@site_notice",site_notice),
                new SqlParameter("@site_copyright",site_copyright),
                new SqlParameter("@site_about",site_about)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 网站参数查询
        public string jhy_site_query()
        {
            DataTable dt = new DataTable();
            string proc = "jhy_site_query";
            dt = SQLHelper.ExecuteQuery(proc, CommandType.StoredProcedure);
            return QXHelper.TableToJson(dt);
        }
        #endregion
        //end 网站配置
        //start 用户管理
        #region 查询用户
        public string jhy_user_query()
        {
            DataTable dt = new DataTable();
            string proc = "jhy_user_query";
            dt = SQLHelper.ExecuteQuery(proc, CommandType.StoredProcedure);
            return QXHelper.LayuiTableJson(dt);
        }
        #endregion
        #region 添加用户
        public bool jhy_user_add(string user_account, string user_name, string user_password)
        {
            bool flag = false;
            string proc = "jhy_user_add";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@user_account",user_account),
                new SqlParameter("@user_name",user_name),
                new SqlParameter("@user_password",user_password)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 删除用户
        public bool jhy_user_delete(string user_id)
        {
            bool flag = false;
            string proc = "jhy_user_delete";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@user_id",user_id)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 修改用户
        public bool jhy_user_edit(string user_id, string user_field, string user_para)
        {
            bool flag = false;
            string proc = "jhy_user_edit";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@user_id",user_id),
                new SqlParameter("@user_field",user_field),
                new SqlParameter("@user_para",user_para)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 查询用户关联角色
        public DataSet jhy_user_role_query(string user_id)
        {
            DataSet ds = new DataSet();
            string proc = "jhy_user_role_query";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@user_id",user_id)
            };
            ds = SQLHelper.ExecuteQueryDataSet(proc,spa,CommandType.StoredProcedure);
            return ds;
        }
        #endregion
        #region 管理用户关联角色
        public bool jhy_user_role_edit(string user_id, string role_id, string field)
        {
            bool flag = false;
            string proc = "jhy_user_role_edit";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@user_id",user_id),
                new SqlParameter("@role_id",role_id),
                new SqlParameter("@field",field)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 用户登录验证
        public string jhy_user_login(string user_account, string user_password)
        {
            DataTable dt = new DataTable();
            string proc = "jhy_user_login";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@user_account",user_account),
                new SqlParameter("@user_password",user_password)
            };
            dt = SQLHelper.ExecuteQuery(proc, spa, CommandType.StoredProcedure);
            return QXHelper.TableToJson(dt);
        }
        #endregion
        #region 查询用户菜单
        public DataSet jhy_user_menu(string user_id, string mg_id)
        {
            DataSet ds= new DataSet();
            string proc = "jhy_user_menu";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@user_id",user_id),
                new SqlParameter("@mg_id",mg_id)
            };
            ds = SQLHelper.ExecuteQueryDataSet(proc, spa, CommandType.StoredProcedure);
            return ds;
        }
        #endregion
        #region 修改密码
        public bool jhy_user_edit_password(string user_id, string user_password)
        {
            bool flag = false;
            string proc = "jhy_user_edit_password";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@user_id",user_id),
                new SqlParameter("@user_password",user_password)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        //end 用户管理

        //start添加访问记录
        #region 添加访问记录
        public bool jhy_browsing_add(string b_ip, string b_url)
        {
            bool flag = false;
            string proc = "jhy_browsing_add";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@b_ip",b_ip),
                new SqlParameter("@b_url",b_url)
            };
            int res = SQLHelper.ExecuteNonQuery(proc, spa, CommandType.StoredProcedure);
            if (res > 0)
            {
                flag = true;
            }
            return flag;
        }
        #endregion
        #region 查询访问记录
        public string jhy_browsing_query(string laypage,string laylimit)
        {
            DataSet ds = new DataSet();
            string proc = "jhy_browsing_query";
            SqlParameter[] spa = new SqlParameter[] {
                new SqlParameter("@laypage",laypage),
                new SqlParameter("@laylimit",laylimit)
            };
            ds = SQLHelper.ExecuteQueryDataSet(proc,spa, CommandType.StoredProcedure);
            return QXHelper.LayuiTablePageJson(ds);
        }
        #endregion
        //end添加访问记录

























    }
}
